
#include "hal_power.h"
#include "hal_pin.h"

static void hal_pin_config(void)
{
	SIU.PCR[PB1_PCR].R = 0x0103;
	//SIU.PCR[PC9_PCR].R = 0x0103;
}

static void hal_standby(void)
{
	ME.RUN[0].R = 0x001F0010u;
	ME.PCTL[68].R = (uint8_t)PCTL_SEL_RUN_PC1;
	ME.PCTL[69].R = (uint8_t)PCTL_SEL_RUN_PC1;
	hal_pin_config();
	WKPU_Config((uint32_t)ME_MODE_STANDBY);			//内部修改唤醒IO口配置
}

static void hal_stop(void)
{
	ME.RUN[0].R = 0x001F0010u;
	ME.PCTL[68].R = ((uint8_t)PCTL_SEL_RUN_PC1 |(uint8_t)PCTL_SEL_LP_PC1);
	ME.PCTL[69].R = ((uint8_t)PCTL_SEL_RUN_PC1| (uint8_t)PCTL_SEL_LP_PC1);
	hal_pin_config();
	WKPU_Config((uint32_t)ME_MODE_STOP);
    while (ME_MODE_STOP == (ME.GS.R & ME_MODE_MASK))
    {
        ;
    }
    ME.RUN[0].R   = 0x001F0074u;
    Mcu_Apply_Mode(ME_MODE_RUN0);
}

void hal_lowpower(power_mode_en mode)
{
	switch(mode)
	{
	case POWER_STANDBY:
		hal_standby();
		break;
	case POWER_STOP:
		hal_stop();
		break;
	default:
		break;
	}
}
